package org.redmagic.service.threading;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.redmagic.Request;
import org.redmagic.location.web.SimpleRedMagicRequest;

/**
 * Takes in a Hierarchical request that contains N properties with an associated hierarchy, and splits it
 * up into N different Hierarchical requests each with 1 property with an associated hierarchy.
 */
public class RedMagicHierarchicalSplitter {
	
	public List<Request> split(Request redMagicRequest) {
		
		List<Request> requests = new ArrayList<Request>(redMagicRequest.getPlaceholders().size());
		
		for (String placeholder : redMagicRequest.getPlaceholders()) {
			Set<String> singlePlaceholder = new HashSet<String>();
			singlePlaceholder.add(placeholder);
			requests.add(new SimpleRedMagicRequest(redMagicRequest.getHierarchy(), singlePlaceholder));
		}
		
		return requests;
	}

}